#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2025/08/01 11:00
# @Author  : Yida Hao
# @File    : pred_joint_action_cli.py

from rclpy.node import Node
from interfaces.srv import PredJointAction
from interfaces.msg import CamImages
from sensor_msgs.msg import JointState

"""
Client for the predict joint action service.
"""

SRV_NAME = 'pred_joint_action_service'

class PredJointActionClient(Node):
    def __init__(self):
        super().__init__(f'{SRV_NAME}_cli')
        self.cli = self.create_client(PredJointAction, SRV_NAME)

        while not self.cli.wait_for_service(timeout_sec=1.0):
            self.get_logger().info('service not available, wating ...')
        
        self.req = PredJointAction.Request()
        
    def send_request(self, cam_imgs: CamImages, states: JointState):
        self.req.cam_images = cam_imgs
        self.req.joint_state = states
        future = self.cli.call_async(self.req)
        return future